package com.wqh.conformity.erupt.entity;

import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SQLDelete;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_erupt.Filter;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.EditType;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.upms.model.base.HyperModel;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;


/**
 * @author wqh
 * @Erupt注解修饰在类上，@EruptField注解修饰在字段上 其他注解均为Jpa注解
 */
@DynamicUpdate
@DynamicInsert
@Data
@Erupt(name = "项目管理",
        filter = @Filter("deleted = false")
)
@Table(name = "t_erupt_project")
@Entity
@SQLDelete(sql = "update t_erupt_project_consignee set deleted = true, deleteTime = now() where id = ?")
public class ProjectEntity extends HyperModel {

    @EruptField(
            views = @View(title = "项目编码"),
            edit = @Edit(title = "项目编码"),
            sort = 0
    )
    private String projectCode;

    @EruptField(
            views = @View(title = "项目名称"),
            edit = @Edit(title = "项目名称"),
            sort = 1
    )
    private String projectName;


    @EruptField(
            views = @View(title = "开始时间"),
            edit = @Edit(title = "开始时间"),
            sort = 2
    )
    private Date startDate;

    @EruptField(
            views = @View(title = "结束时间"),
            edit = @Edit(title = "结束时间"),
            sort = 3
    )
    private Date endDate;

    @EruptField(
            views = @View(title = "项目负责人"),
            edit = @Edit(title = "项目负责人"),
            sort = 4
    )
    private String projectCharge;

    @EruptField(
            views = @View(title = "联系电话"),
            edit = @Edit(title = "联系电话"),
            sort = 4
    )
    private String chargePhone;

    private Date deleteTime;

    private Boolean deleted = false;

    @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
    @JoinColumn(name = "project_id")
    @OrderBy
    @EruptField(
            edit = @Edit(title = "联系人管理", type = EditType.TAB_TABLE_ADD)
    )
    private Set<ProjectConsigneeEntity> projectConsigneeEntities;
}